package com.emr.web.controller.emr;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.emr.common.annotation.Log;
import com.emr.common.enums.BusinessType;
import com.emr.module.domain.Zlsqdan;
import com.emr.module.service.IPersonalService;
import com.emr.module.service.IZlsqdanService;
import com.emr.system.service.ISysDeptService;
import com.emr.system.service.ISysUserService;
import com.emr.web.core.base.BaseController;
import com.emr.framework.web.page.TableDataInfo;
import com.emr.common.base.AjaxResult;

/**
 * 治疗申请单 信息操作处理
 * 
 * @author emr
 * @date 2019-02-21
 */
@Controller
@RequestMapping("/module/zlsqdan")
public class ZlsqdanController extends BaseController
{
    private String prefix = "module/zlsqdan";
	
	@Autowired
	private IZlsqdanService zlsqdanService;
	@Autowired
	private IPersonalService ipersonalService ;
	
	@Autowired
    private ISysUserService userService;
	@Autowired
    private ISysDeptService sysDeptService;
	
	@RequiresPermissions("module:zlsqdan:view")
	@GetMapping()
	public String zlsqdan()
	{
	    return prefix + "/zlsqdan";
	}
	
	/**
	 * 查询治疗申请单列表
	 */
	@RequiresPermissions("module:zlsqdan:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Zlsqdan zlsqdan)
	{
		startPage();
		if("".equals(zlsqdan.getBingrenName())){
			zlsqdan.setBingrenName(null);
		}
        List<Zlsqdan> list = zlsqdanService.selectZlsqdanList(zlsqdan);
		return getDataTable(list);
	}
	
	/**
	 * 新增治疗申请单
	 */
	@GetMapping("/add")
	public String add(ModelMap mmap)
	{
		mmap.put("posts",ipersonalService.selectIcdAll());
		mmap.put("yisheng", userService.selectyishengAll());
		mmap.put("bumen", sysDeptService.selectDeptAll());
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存治疗申请单
	 */
	@RequiresPermissions("module:zlsqdan:add")
	@Log(title = "治疗申请单", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Zlsqdan zlsqdan)
	{		
		return toAjax(zlsqdanService.insertZlsqdan(zlsqdan));
	}

	/**
	 * 修改治疗申请单
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Zlsqdan zlsqdan = zlsqdanService.selectZlsqdanById(id);
		mmap.put("posts", ipersonalService.selectUPersonalByIds(zlsqdan.getBingrenId()));
		mmap.put("yisheng", userService.selectyishengAlls(zlsqdan.getYishengid()));
		mmap.put("keshi", sysDeptService.selectDeptByIds(zlsqdan.getZhiliaokeshi()));
		mmap.put("zlsqdan", zlsqdan);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存治疗申请单
	 */
	@RequiresPermissions("module:zlsqdan:edit")
	@Log(title = "治疗申请单", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Zlsqdan zlsqdan)
	{		
		return toAjax(zlsqdanService.updateZlsqdan(zlsqdan));
	}
	
	/**
	 * 删除治疗申请单
	 */
	@RequiresPermissions("module:zlsqdan:remove")
	@Log(title = "治疗申请单", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(zlsqdanService.deleteZlsqdanByIds(ids));
	}
	
}
